package exercise.jslide.jslide.model.shapes;

import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;

public class Circle extends Shape {

    @Override
    protected void drawShape(GraphicsContext gc) {
        double radius = Math.max(width, height) / 2;
        gc.fillOval(x, y, radius*2, radius*2);
        gc.strokeOval(x, y, radius*2, radius*2);
    }

    @Override
    public boolean contains(Point2D point) {
        double centerX = x + width / 2;
        double centerY = y + height / 2;
        double radius = Math.min(width, height) / 2;

        double distance = Math.sqrt(
                Math.pow(point.getX() - centerX, 2) +
                        Math.pow(point.getY() - centerY, 2)
        );

        return distance <= radius;
    }

    @Override
    public Circle clone() {
        Circle circle = new Circle();
        circle.x = this.x;
        circle.y = this.y;
        circle.width = this.width;
        circle.height = this.height;
        circle.fillColor = this.fillColor;
        circle.strokeColor = this.strokeColor;
        circle.strokeWidth = this.strokeWidth;
        return circle;
    }
}